import { getMongoManager, getMongoRepository,  } from "typeorm";

import { Users } from "../models/User";

class UserServer {


  find(skipNum: number, limit: number) {
    const userRepository = getMongoRepository(Users);
    return userRepository.find({
      skip: skipNum,
      take: limit
    })
  }

  save(data: Users) {
    const userRepository = getMongoRepository(Users);
    return userRepository.save(data);
  }

  findOneByPhone(phone: number) {
    const userRepository = getMongoRepository(Users);
    return userRepository.findOne({ phone })
  }

  async userCount() {
    const userRepository = getMongoRepository(Users);
    const [users, count] = await userRepository.findAndCount()
    return count
  }
}

export default new UserServer()